1000 GOSUB 1930 'cs
1010 PRINT:PRINT TAB(28);"DLETTERS March 20, 1982
1015 ' by Dan Dugan -- public domain
1020 PRINT:PRINT"In this program you control printing in the same way that
1030 PRINT"you control listing on the screen in DEDIT.  The 'pause prompt'
1040 PRINT"Ready> will accept SPACE or RETURN to print, 'z' to print and keep
1050 PRINT"going without pausing, or ESCAPE to abort and return to DEDIT.
1051 PRINT:PRINT"It will also accept two commands special to the letters
1052 PRINT"program.  'r' will cause the previous letter to repeat, and
1053 PRINT"'n' will ask for a record number to start from.
1060 PRINT:PRINT"While printing without pause, hitting the space bar during
1070 PRINT"a letter will cancel the 'z' and cause the program to pause before
1080 PRINT"starting the next letter.
1090 ON ERROR GOTO 1780
1100 DEFINT A-Z
1110 COMMON I,J,K,X,Y,T$,R$,S$,T1$,SKIPPARSE,FT,SEARCH,

	C,N,NC,P6,P7,P8,P9,PI,S,T,T1,T2,C(),B$(),N$(),

	SEARCHWORD$(),SEARCHFIELD(),SKIPWORD$(),LOOKFIELD(),DD$(),F$,FT$
1130 GOTO 1160
1140 PRINT:PRINT"Wait while editor program is re-loaded
1150 CHAIN DD$(1)+"DEDIT",1000
1160 '



				PRINT LETTER SET-UP


1170 INPUT"Enter text file name (use prefix: to identify disk)"; G$
1180 IF G$="x" OR G$="" THEN 1670
1190 X$=G$: GOSUB 1810 ' UCV
1200 G$=Y$
1210 OPEN "I",3,G$ ' test
1220 CLOSE 3
1230 '




				RECORD WORK LOOP


1240 C2=0 ' first time
1250 '
1260 FOR I=T1 TO T2 '		<==== FOR
1270 GOSUB 2510 ' get rec
1280 IF ASC(T$)=0 THEN PRINT"0";:GOTO 1640

	ELSE PRINT"+";
1290 T1$=T$ ' save it
1300 IF SKIPPARSE=1 THEN 1320
1310 GOSUB 1690 ' parse record string
1320 IF SEARCH=0 THEN 1620
1330 '



				SEARCH


1340 IF SEARCH<>2 THEN 1410
1350 IF INSTR(T$,SEARCHWORD$(0))=0 THEN 1640
1360 '

	speed search
1370 LPRINT CHR$(7); ' found it
1380 GOSUB 1690 ' parse
1390 GOTO 1620
1400 '

	field search
1410 J=0 '			check for skips first
1420 IF SKIPWORD$(J)="" THEN 1500 ' try search then
1430 IF LOOKFIELD(J)<>0 THEN 1470 ' look in field
1440 IF INSTR(T1$,SKIPWORD$(J))<>0 THEN 1640
1450 J=J+1
1460 GOTO 1420
1470 IF INSTR(B$(LOOKFIELD(J)),SKIPWORD$(J))<>0 THEN 1640
1480 J=J+1
1490 GOTO 1420
1500 IF SEARCHWORD$(0)="" THEN 1600 ' don't care so print it
1510 J=0: GOTO 1530 '		now search
1520 IF SEARCHWORD$(J)="" THEN 1640
1530 IF SEARCHFIELD(J)<>0 THEN 1570 ' field
1540 IF INSTR(T1$,SEARCHWORD$(J))<>0 THEN 1600 ' found it
1550 J=J+1
1560 GOTO 1520
1570 IF INSTR(B$(SEARCHFIELD(J)),SEARCHWORD$(J))<>0 THEN 1600
1580 J=J+1
1590 GOTO 1520
1600 LPRINT CHR$(7);
1610 IF SKIPPARSE=1 THEN GOSUB 1690 ' parse
1620 '


				zag to do it
1630 GOTO 1960
1640 '


				END OF RECORD WORK LOOP


1650 IPREV=I ' for repeat command
1660 NEXT
1670 '


				FINISH


1680 GOTO 1140 ' exit
1690 '




				(SUB) PARSE STRING


1700 K=0
1710 J=INSTR(T$,CHR$(126)) ' delimiter
1720 IF J=0 THEN RETURN
1730 K=K+1
1740 B$(K)=MID$(T$,1,J-1)
1750 T$=MID$(T$,J+1)
1760 GOTO 1710
1770 '


				ERROR HANDLING


1780 IF ERL=1210 AND ERR=53 THEN CLOSE 3:PRINT"FILE NOT FOUND": RESUME 1160
1790 IF ERL=1210 AND ERR=64 THEN CLOSE 3:PRINT"UNACCEPTABLE FILE NAME": RESUME 1160
1800 ON ERROR GOTO 0
1810 '



				(SUB) UCV


1820 Y$=""
1830 FOR J=1 TO LEN(X$)
1840	Y$=Y$+" "
1850	X=ASC(MID$(X$,J, 1))
1860	IF 96<X AND X<123 THEN MID$(Y$,J,1)=CHR$(X-32): GOTO 1880
1870	MID$(Y$,J,1)=MID$(X$,J,1)
1880 NEXT J
1890 RETURN
1900 '



				(SUB) EXIT TEST

				returns char. in X


1910 X$=INKEY$:X=0
1911 IF X$<>"" THEN X=ASC(X$)
1915 IF X=27 THEN CLOSE 3:GOTO 1670	' use ESC to escape listing
1920 RETURN
1930 '



				(SUB) CLEAR SCREEN (TERM DEP)


1940 PRINT CHR$(12);
1950 RETURN
1960 '



				PRINT LETTER (insert above)


1970 '


		PAUSE CONTROLS		(TERM DEP if uppercase) 


1980 GOSUB 1900 ' exit
2000 IF X=122 THEN 2090			' go on
2010 PRINT I;B$(1);TAB(20);"Ready>";
2020 A$=INPUT$(1):PRINT A$
2030 IF A$=CHR$(13) OR A$=CHR$(32) THEN 2090
2040 IF A$="z" THEN 2090
2050 IF A$="r" THEN I=IPREV:GOTO 1270
2060 IF A$="n" THEN 2070 ELSE 2080
2070 INPUT"Enter number of desired record:  ";I:GOTO 1270
2080 GOTO 1970			' loop
2090 '


		DO IT


2100 C1=0		'counts data lines
2110 OPEN "I",3,G$ ' open each time to restore
2120 IF P9=0 THEN GOSUB 1930 ' clear screen
2130 IF EOF(3) THEN 2140 ELSE 2180
2140 '


		END OF TEXT FILE


2150	IF P9=1 THEN LPRINT CHR$(12); ' form feed
2160	CLOSE 3
2170	GOTO 1640 ' next record
2180 '


		GET LINE & TEST


2190 LINE INPUT #3,L$
2200 IF LEFT$(L$,3)=".da" THEN 2210 ELSE 2450
2210 '


		LINE IS DATA LINE


2220 C1=C1+1:IF C1>NC THEN 2130
2230 ON C1 GOTO 2240, 2310, 2340, 2370, 2400, 2430 ' six lines
2240 '


		FIRST DATA LINE


2250 IF B$(1)="" AND B$(2)="" THEN 2300
2260 IF B$(1)="" THEN A$=B$(2):GOTO 2300
2270 IF B$(2)="" THEN A$=B$(1):GOTO 2300
2280 A$=B$(2)+CHR$(32)+B$(1)
2290 GOSUB 2480
2300 GOTO 2130
2310 '


		DATA LINE 2


2320 IF B$(3)="" THEN 2130
2330 A$=B$(3):GOSUB 2480:GOTO 2130
2340 '


		DATA LINE 3


2350 IF B$(4)="" THEN 2130
2360 A$=B$(4):GOSUB 2480:GOTO 2130
2370 '


		DATA LINE 4


2380 IF B$(5)="" THEN 2130
2390 A$=B$(5):GOSUB 2480:GOTO 2130
2400 '


		DATA LINE 5


2410 A$=B$(6)+CHR$(32)+B$(7)
2420 GOSUB 2480:GOTO 2130
2430 '


		DATA LINE 6


2440 A$=B$(10):GOSUB 2480:GOTO 2130
2450 '


		PRINT TEXT LINE


2460 IF P9 THEN LPRINT L$ ELSE PRINT L$
2470 GOTO 2130
2480 '


		(SUB) PRINT DATA LINE


2490 IF P9 THEN LPRINT A$ ELSE PRINT A$
2500 RETURN
2510 '



				GET RECORD "I" IN T$ SUB


2520 T$="" ' necessary!
2530 ON FT GOTO 2560,2540
2540	GET#1,FT*I+2 ' latter half
2550	T$=LEFT$(R$,127)
2560	GET#1,FT*I+1 ' whole or first half
2570	T$=R$+T$
2580 RETURN
